package dao

import (
	"ssims/models"
)

func GetAllDescribe(describe map[string]interface{}) (error, []models.Describe, int64) {
	var describeData []models.Describe
	page := describe["page"].(int)
	pageSize := describe["limit"].(int)
	searchName := describe["searchName"].(string)
	var total int64
	err := db.Table("describe").Select("describe_no, describe_name, time, type, describe, update_time").Where("describe_name like ? and is_del = false", searchName+"%").Order("describe_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&describeData).Error
	return err, describeData, total
}

func DelDescribe(id string) error {
	// var Describe []models.Describe
	err := db.Table("describe").Where("describe_no = ?", id).Update("is_del", true).Error
	return err
}

func UpdateDescribe(describe models.Describe) error {
	err := db.Table("describe").Where("describe_no = ?", describe.DescribeNo).Updates(&describe).Error
	return err
}

func AddDescribe(describe models.Describe) error {
	err := db.Table("describe").Select("describe_no", "describe_name", "time", "type", "describe", "update_time", "is_del").Create(&describe).Error
	return err
}
